package com.sgb.kjwl.viewmodel.home;

import com.sgb.kjwl.AppConstant;
import com.sgb.kjwl.api.APIManager;
import com.sgb.kjwl.model.entity.transport.CategoryItem;
import com.sgb.kjwl.repository.HomeRepertory;
import com.sgb.kjwl.view.ui.activity.home.SearchActivity5;
import com.swgk.core.base.BaseViewModel;
import com.swgk.core.base.model.entity.BaseEntity;
import com.swgk.core.dialog.DialogHelper;
import com.swgk.core.util.MLog;
import com.swgk.core.util.MToast;

import java.util.List;

import retrofit2.Call;
import retrofit2.Callback;
import retrofit2.Response;

public class SearchModel5 extends BaseViewModel {
    private SearchActivity5 activity;
    private HomeRepertory repertory;
    private static final String TAG = "SearchModel4";

    public SearchModel5(SearchActivity5 activity, HomeRepertory repertory) {
        this.activity = activity;
        this.repertory = repertory;
    }

    public void searchCategory() {
        APIManager.getInstance().getCommonAPI().searchCategoryItems().enqueue(new Callback<BaseEntity<List<CategoryItem>>>() {
            @Override
            public void onResponse(Call<BaseEntity<List<CategoryItem>>> call, Response<BaseEntity<List<CategoryItem>>> response) {
                DialogHelper.dismissProgressDialog();
                if (response.body() == null) {
                    activity.showTab(null);
                    return;
                }
                if (response.body().getState().equals(APIManager.RESPONSE_OK)) {
                    activity.showTab(response.body().getData());
                } else {
                    MToast.showToast(activity, response.message());
                }
            }

            @Override
            public void onFailure(Call<BaseEntity<List<CategoryItem>>> call, Throwable t) {
                DialogHelper.dismissProgressDialog();
                MLog.d(AppConstant.API_LOG, "error " + t.getMessage());
            }
        });

    }


}
